package com.common.action;

import com.common.model.Admin;
import com.common.model.User;
import com.common.service.AdminService;
import com.common.service.UserService;

public class LoginAction extends BaseAction {
	private AdminService adminservice;
	private UserService userservice;
	private Admin admin;
	private User user;
	private boolean flag;
	private String message;
	private String status;

	public String login() {
	
		//管理员身份登陆
		if (status.equals("2")) {
			flag = adminservice.login(admin.getUsername(), admin.getPassword());
			
			if (flag) {
				return SUCCESS;
			} else {
				message = "用户名或密码错误";
				return "login";
			}
		}
	
		//报修人员
		else if(status.equals("0")){
		 user = userservice.bLogin(admin.getUsername(), admin.getPassword());
			if (user!=null) {
				//跳转到报修人员对应的页面
				return "baoxiu";
			} else {
				message = "用户名或密码错误";
				return "login";
			}
		}
		//维修人员
		else if(status.equals("1")){
		 user = userservice.wLogin(admin.getUsername(), admin.getPassword());
			if (user!=null) {
				//跳转到维修人员对应的页面
				return "weixiu";
			} else {
				message = "用户名或密码错误";
				return "login";
			}
		}
		
		return null;
	}

	public AdminService getAdminservice() {
		return adminservice;
	}

	public void setAdminservice(AdminService adminservice) {
		this.adminservice = adminservice;
	}

	public Admin getAdmin() {
		return admin;
	}

	public void setAdmin(Admin admin) {
		this.admin = admin;
	}

	public boolean isFlag() {
		return flag;
	}

	public void setFlag(boolean flag) {
		this.flag = flag;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public UserService getUserservice() {
		return userservice;
	}

	public void setUserservice(UserService userservice) {
		this.userservice = userservice;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	
}
